package org.example.com.Demo;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

@Component
@Slf4j
public class SetRedisDemo {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    public void a(){
        SetOperations<String, String> set = stringRedisTemplate.opsForSet();
        set.add("A", "aa","bb","cc","dd","ee","11","22","33","44","55");
        set.add("B","bb","cc","dd","ee");
        set.add("C","cc","dd","ee","22","33");
    }
    public void b(){
        SetOperations<String, String> set = stringRedisTemplate.opsForSet();
        Set<String> all=set.members("A");
        String v1=set.randomMember("A");
        List<String>list=set.randomMembers("A",4);
        Set<String > set1=set.distinctRandomMembers("A",4);
        log.info("all:{}",all);
        log.info("v1:{}",v1);
        log.info("list:{}",list);
        log.info("set1:{}",set1);
    }
    public void c(){
        SetOperations<String, String> set = stringRedisTemplate.opsForSet();
        Long size=set.size("A");
        Set<String> set1=set.difference("B","C");
        Set<String> set2=set.union("B","C");
        Set<String> set3=set.intersect("B","C");
        log.info("set2:{}",set2);
        log.info("set3:{}",set3);
        log.info("set1:{}",set1);
    }
}
